package cn.edu.scau.cmi.mengzhuorong.adapterOfClass;

import java.util.ArrayList;
import java.util.List;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class AdapterOfClassController extends AdapterOfClass {

	@FXML
	private Button btn_class;
	@FXML
	private TextField text_ID,text_name;
	@FXML
	private Label label_list;
	
	int ID;
	String name;
	List<Student> stuList = new ArrayList<Student>();
	List<Integer> stuIdList = null;
	public void eventButton() {
		String NameList = null;
		ID = Integer.valueOf(text_ID.getText());
		name = text_name.getText();
		Student student = new Student(ID, name);
		stuList.add(student);
		if(stuList!=null) {
			stuIdList = studentList(stuList);
			stuIdList = sortInt(stuIdList);
		}
		for( int i = 0; i < stuList.size(); i++) {
			System.out.println(stuList.get(i).ID+" "+stuList.get(i).name);
		}
		
		for(int i = 0; i < stuIdList.size(); i++) {
			for(int j = 0; j < stuList.size(); j++) {
				if(stuList.get(j).ID == stuIdList.get(i)) {
					if(NameList == null)
					NameList = String.valueOf(stuList.get(j).ID) + " " + stuList.get(j).name+"\n";
					else NameList = NameList + String.valueOf(stuList.get(j).ID) + " " + stuList.get(j).name+"\n";
				}
			}
		}
		label_list.setText(NameList);
		
	}
}
